home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / BST_SystemDocs.lha / BeastV1 / Examples / BST_System / BST_Example1.txt < prev    next >
Encoding:
Text File  |  1996-03-31  |  3.3 KB  |  70 lines

  1.  
  2. Example1.c
  3. ==========
  4.  
  5. This example program creates a simple class and creates an object
  6. of it.
  7.  
  8. How it works
  9. ------------
  10.  
  11. Also see the ROBODocs (AutoDoc) for more information about the beast library
  12. functions.
  13.  
  14. * my_class defines the pointer to the Beast Class (struct BST_Class) ,_NEVER_
  15. use the BST_Class structure items directly, it _will_ change in the future.
  16.  
  17. * my_object defines the pointer to the Beast Object (struct BST_Object), also the
  18. same story, never use the BST_Object items.
  19.  
  20. * The beast.library is opened, BeastBase now points to the opened beast.library.
  21.  
  22. * The BST_MakeClass function is use to define this small class.
  23.   The first parameter is the public name of the class, which in our case is
  24.   "my_firstclass". The second parameter is the size of our instance in bytes.
  25.   A instance is defined by the struct my_class_instance, we want only two elements
  26.   LONG X and LONG Y, so our instance size is 8 bytes.
  27.  
  28. * Now it's time add a method to our class. Look at the CLSS_AddMethod description
  29.   for more information. For this example we choose a standard BEAST method ID,
  30.   OBM_INIT. Our method routine is declared as my_init.
  31.   To declare this routine the rfcall() macro is used (Beast.h).
  32.   
  33. * To add the class to the Beast system we use the BST_AddClass function. Now everybody
  34.   can use this class. If you have the full BFS (BeastFileSystem) package you can
  35.   assign a class to be used by only a certain group(s) of users.
  36.  
  37. * Finally we are ready to create an object from our class. OBJ_NewObject has three
  38.   parameters, the first is always NULL, and mostly for internal use. The second
  39.   is a pointer to the class name and the third one is very important, 'under' this
  40.   object the new object is created. In this way a dynamic object tree is build.
  41.   We set this parameter to NULL. This means that the object is created under the
  42.   root of the Beast-object tree. If you have (again) the full BFS-package the object
  43.   will be added under the BFS_UserClass of the logged in user.
  44.  
  45. * The OBJ_NewObject _only_ adds the Object. No initialization of the instance is done.
  46.   But gladly our 'my_init' routine does the job. The first two parameters are 
  47.   straightforward, the third is the most important, this is the TagList which is
  48.   used by the method routine. In our example 'my_init' doesn't use any parameters
  49.   of the TagList so we send an empty list (EmptyList). The fourth parameter are the
  50.   MethodFlags, in our simple example they are 0. See the OBJ_DoMethod function for
  51.   more information or the Docs/BST_System/Method.txt file.
  52.  
  53. * We now enter the 'my_init' routine. The first we do is to get the pointer to our
  54.   instance (Macro_GetInstance). Now we can manipulate the instance elements.
  55.  
  56. * When we leave our method routine we _must_ return with the MethodFlags, because
  57.   we aren't aware which flags are set. We _can_ however reset or set some flags.
  58.   
  59. * Right, this is enough let's dump this object. Very simple, we use the
  60.   OBJ_DisposeObject function. This function simply removes the object.
  61.   
  62. * After this the class can be disposed, BST_RemoveClass and BST_FreeClass. The added
  63.   method is also disposed by the BST_FreeClass. The methods can also be removed
  64.   with the CLSS_DisposeMethod function. In this way the classes methods can be altered
  65.   _run time_.
  66.  
  67. * The CloseLibrary ends our example program.
  68.  
  69.  
  70.